import 'dart:convert';

import 'package:casdon/modules/login/data/api/login_api.dart';
import 'package:casdon/modules/login/data/repository/auth_repository.dart';
import 'package:casdon/modules/login/domain/validators/input_validator.dart';
import 'package:flutter/widgets.dart';

class LoginUsecase {
  final AuthRepository repository;
  final InputValidator validator;
  
  const LoginUsecase(this.repository, this.validator);

  Future<ResponseLogin> execute(RequestLogin request) async {

    final jsonStr = jsonEncode(request.toJson());
    debugPrint('Request JSON: $jsonStr');

    if (request.grantType == LoginGrantType.password.name
     && request.userName != null
     && validator.isValude(request.userName!) == false)
    {
       throw "账号格式不正确";
    }
    return repository.login(request);
  }
}